package com.ha7419x.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class FactoryForStrategy {

    @Autowired
    private Map<String, Strategy> factory = new ConcurrentHashMap<>();

    public Strategy getStrategy(String key) {
        Strategy strategy = factory.get(key);
        if (strategy == null) {
            throw new RuntimeException("no strategy defined");
        }
        return strategy;
    }

}
